package com.team.RunsFast_Api.controller;

import com.team.RunsFast_Api.config.SystemConfig;
import com.team.RunsFast_Api.dto.CartAddDto;
import com.team.RunsFast_Api.dto.CartUpdateDto;
import com.team.RunsFast_Api.service.intf.CartService;
import com.team.runsfast.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping("/api/cart/")
@CrossOrigin
@Api(tags = "购物车相关操作")
public class CartController {
    @Autowired
    private CartService service;

    /**查询*/
    @GetMapping("all.do")
    public R all(){
        return service.queryAll();
    }

    /**加入购物车*/
    @PostMapping("join.do")
    public R join(@RequestBody CartAddDto dto, HttpServletRequest request){
        return service.add(dto,request.getHeader(SystemConfig.HEADER_TOKEN));
    }
    /**更改购物车中商品的数量*/
    @PostMapping("update.do")
    public R update(@RequestBody CartUpdateDto dto, HttpServletRequest request){
        return service.updateNum(dto);
    }
    /**删除购物车中的商品*/
    @GetMapping("del.do")
    public R del(long id){
        return service.del(id);
    }
    /**查询我的购物车*/
    @GetMapping("my.do")
    public R my(HttpServletRequest request){
        return service.queryMy(request.getHeader(SystemConfig.HEADER_TOKEN));
    }
}